<template>
  <div class="register">
    <mt-header title="注册">
      <router-link to slot="left">
        <mt-button icon="back" @click="$router.go(-1)"></mt-button>
      </router-link>
    </mt-header>

    <Form class="registerForm" ref="registerForm" :model="formData" :rules="rules" @keydown.enter="handleSubmit">
      <mt-field placeholder="请输入用户名" v-model="formData.nickName"></mt-field>
      <mt-field placeholder="请输入密码" v-model="formData.pwd" type="password"></mt-field>
      <mt-field placeholder="请再次输入密码" v-model="formData.pwd2" type="password"></mt-field>
      <mt-field placeholder="所在城市" v-model="formData.cityName"></mt-field>
    </Form>
    
    <div class="button">
        <mt-button type="primary" size="large" @click.native="handleSubmit">注册</mt-button>
      </div>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "register",
  data() {
    return {
      formData: {
        nickName: "",
        pwd: "",
        cityId:"",
        cityName: "",
      },
      rules: {
        nickName: [
          { required: true, message: "请输入用户名", trigger: "blur" }
        ],
        pwd: [
          { required: true, message: "请输入密码", trigger: "blur" }
          // { type: 'string', min: 6, message: '密码长度必须大于6位', trigger: 'blur' }
        ]
      },
    };
  },
  methods: {
    handleSubmit() {
      axios.post("/api/user/register", this.formData).then(res => {
        console.log(res);
        this.$router.push("/login");
      });
    }
  }
};
</script>

<style lang="stylus" scoped>
@import '~@/assets/style/modifyMintUIColor.styl';

.register {
  background-color #fff;
  height 100%;

  .registerForm {
    margin-top 10px;
  }
  >>> .mint-cell:last-child {
    background: none;
  }

  >>> .mint-cell-wrapper {
    border-radius: 4px;
    border: solid 1px $themeColor;
    margin: 10px;
    background: none;
  }

  .button {
      padding: 0.2rem;
    }
}
</style>